const app = getApp()
Page({
  data: {
    unread: {
      total: 0,
      announce: 0,
      remind: 0
    }
  },
  changeToRead(){
    var that = this
    wx.showModal({
      title: '确认',
      content: '是否将所有消息设为已读',
      success: function(res) {
        if(res.confirm){
          // 点击了确认
          var unread = {
            total: 0,
            email: 0,
            wuye: 0,
            linli: 0,
            jiazheng: 0,
            jianyan: 0,
            jingwu: 0
          }
          that.setData({
            unread
          })
          console.log('用户点击确定')
        } else {
          console.log('用户点击取消')
        }
      }
    })
  },
  goToPage(e){
    wx.navigateTo({
      url: '/pages/information/detail/detail?type=' + e.currentTarget.dataset.type
    })
  },

  getUnreadMessageCount() {
    app.sendGetRequest('/community/message/getMessageCount', (res) => {
      console.log(res)
      if(res.code == 200) {
        let unread = {
          announce: res.data.announce,
          remind: res.data.remind,
          total: res.data.announce + res.data.remind
        }
        this.setData({
          unread
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    /* 初始化各类消息未读数量 */
    this.getUnreadMessageCount()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})